// src/api/business/group.ts
import { Alova } from '@/utils/http/alova/index';

// 班组信息数据结构
interface GroupInfo {
  color: string;
  groupId: string;
  groupName: string;
  memberList: GroupMember[];
  monitor: string;
  monitorName: string;
  orgArray: string;
  orgArrayName: string;
  orgId: string;
  orgName: string;
  remark: string;
}

// 班组成员信息
interface GroupMember {
  groupId: string;
  groupMemberId: string;
  memberId: string;
}

// 分页查询结果结构
interface PageResult<T> {
  records: T[];
  total: number;
  size: number;
  current: number;
  orders: any[];
  optimizeCountSql: boolean;
  searchCount: boolean;
  countId: string | null;
  maxLimit: string | null;
  pages: number;
}

const baseApi = '/web/ser/group';

/**
 * 获取班组列表
 */
export function getGroupList(params: any) {
  return Alova.Post<InResult<PageResult<GroupInfo>>>(baseApi + '/page', { params });
}

/**
 * 添加班组
 */
export function addGroup(params: Partial<GroupInfo>) {
  return Alova.Post<InResult<GroupInfo>>(baseApi + '/addRecord', { params });
}

/**
 * 更新班组信息
 */
export function updateGroup(params: Partial<GroupInfo> & { groupId: string }) {
  return Alova.Post<InResult<GroupInfo>>(baseApi + '/updateRecord', { params });
}

/**
 * 删除班组
 */
export function deleteGroup(params: { groupId: string } | { groupIds: string[] }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/deleteRecord', { params });
}

/**
 * 批量删除班组
 */
export function batchDeleteGroups(groupIds: string[]) {
  return Alova.Post<InResult<boolean>>(baseApi + '/batchDeleteRecords', { groupIds });
}

/**
 * 获取班组详情
 */
export function getGroupDetail(groupId: string) {
  return Alova.Post<InResult<GroupInfo>>(baseApi + '/getRecord', { groupId });
}

/**
 * 获取班组成员列表
 */
export function getGroupMembers(groupId: string) {
  return Alova.Post<InResult<GroupMember[]>>(baseApi + '/getMembers', { groupId });
}

/**
 * 添加班组成员
 */
export function addGroupMember(params: { groupId: string, memberId: string }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/addMember', params);
}

/**
 * 批量添加班组成员
 */
export function batchAddGroupMembers(params: { groupId: string, memberIds: string[] }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/batchAddMembers', params);
}

/**
 * 删除班组成员
 */
export function deleteGroupMember(params: { groupId: string, memberId: string }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/deleteMember', params);
}

/**
 * 批量删除班组成员
 */
export function batchDeleteGroupMembers(params: { groupId: string, memberIds: string[] }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/batchDeleteMembers', params);
}